package com.appkubes.mall.admin.application.system.config.service.impl;

import com.appkubes.mall.admin.application.system.config.dao.ConfigDao;
import com.appkubes.mall.admin.application.system.config.service.ConfigService;
import com.appkubes.mall.core.entity.MallSystemConfig;
import com.appkubes.mall.core.service.impl.BaseMallSystemConfigServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Rongjie
 * @Date: 2020/1/18 21:56
 * @Description:
 */
@Service
public class ConfigServiceImpl extends BaseMallSystemConfigServiceImpl implements ConfigService {
    @Resource
    ConfigDao configDao;


    @Override
    public String getConfigValue(String globalConfigKey) {
        MallSystemConfig config = findByGlobalKey(globalConfigKey);
        if (config != null) {
            return config.getConfigValue();
        }
        return null;
    }


    private MallSystemConfig findByGlobalKey(String globalConfigKey) {
        MallSystemConfig query = new MallSystemConfig();
        query.setGlobalConfigKey(globalConfigKey);
        List<MallSystemConfig> mallSystemConfigList = this.selectListByEntity(query);
        if (mallSystemConfigList.size() == 0) return null;
        return mallSystemConfigList.get(0);
    }
}
